package com.yuerlive.rainbow.module.game;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.yuerlive.rainbow.R;
import com.yuerlive.rainbow.base.BaseFragment;
import com.yuerlive.rainbow.base.BasePresenter;
import com.yuerlive.rainbow.entity.Gift;
import com.yuerlive.rainbow.entity.LiveDetailData;
import com.yuerlive.rainbow.observer.Observerable;
import com.yuerlive.rainbow.observer.ObserverableType;
import com.yuerlive.rainbow.widget.CustomDialog;

import java.util.List;

import butterknife.BindArray;

/**
 * Created by xiaoyi on 2017/7/4.
 */

public abstract class FragmentGameBase<T extends BasePresenter> extends BaseFragment implements Observerable.ISubscribe {
    public abstract boolean isDialogShowing();

    public abstract void setLiveDetail(LiveDetailData liveDetailData);

    protected int switchGameID = -1;

    protected boolean shouldNotChange;


    @BindArray(R.array.win_gift_ids)
    protected int[] winGifts;

    protected int GAMESTATE = 0;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Observerable.getInstance().subscribe(ObserverableType.SWITCHGAME, this);
        Observerable.getInstance().subscribe(ObserverableType.EXITLIVEROOM, this);
    }

    @Override
    public <T> void update(ObserverableType key, T data) {
        switch (key){
            case  SWITCHGAME:
                switchGameID = (Integer) data;
                break;
            case EXITLIVEROOM:
                shouldNotChange = true;
                break;
        }

    }

    @Override
    public void onDestroy() {
        Observerable.getInstance().unSubscribe(ObserverableType.SWITCHGAME, this);
        Observerable.getInstance().unSubscribe(ObserverableType.EXITLIVEROOM, this);
        super.onDestroy();
    }

    protected Gift findGiftById(List<Gift> gifts, int id) {
        for (Gift gift : gifts) {
            if (gift.getId() == id)
                return gift;
        }
        return null;
    }




}
